<!-- 支付结果 1=待付款， 2=待发货， 3=待收货， 4=待评价，5=退款中，6=已退款，7=已取消 -->
<template>
	<view class="page">
		<view class="container" v-if="order.status == 1 || order.status == 2">
			<view v-if="order.status == 2" class="status-icon success iconfont">&#xe62e;</view>
			<view v-if="order.status == 1" class="status-icon fail iconfont">&#xe62d;</view>
			<text v-if="order.status == 2" class="pay-text">支付成功</text>
			<text v-if="order.status == 1" class="pay-text">订单未支付</text>
			<view class="descriptions">
				<view class="descriptions-item">
					<text class="label">下单时间</text>
					<text class="text">{{order.create_time}}</text>
				</view>
				<view class="descriptions-item">
					<text class="label">支付方式</text>
					<text class="text">微信</text>
				</view>
				<view class="descriptions-item">
					<text class="label">支付金额</text>
					<text class="text">￥{{order.payment}}元</text>
				</view>
				<view class="descriptions-item" v-if="order.status == 1">
					<text class="label">失败原因</text>
					<text class="text">取消支付</text>
				</view>
			</view>
			<view class="btn-group">
				<button class="btn fill-btn" @click="handleCheckOrder()">查看订单</button>
				<button class="btn border-btn" @click="handleBackToHome()">返回首页</button>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import { onLoad } from "@dcloudio/uni-app";

	const order = ref({});

	onLoad(() => {
		getDetail();
	});

	// 获取订单详情
	const getDetail = async () => {

		order.value = {
			status: Math.random() > 0.7 ? 1 : 2,
			create_time: '2024-10-07 12:40:22',
			payment: '36.2'
		};

		uni.setNavigationBarTitle({
			title: order.value.status == 1 ? '支付失败' : '支付成功'
		});
	}

	// 查看订单
	const handleCheckOrder = () => {
		uni.redirectTo({
			url: '/pagesC-order/order-detail/index'
		})
	}

	// 返回首页
	const handleBackToHome = () => {
		uni.reLaunch({
			url: '/pages/index/index'
		})
	}
</script>

<style lang="scss" scoped>
	$redColor: #FE3333;
	$greenColor: #40c100;

	.page {
		padding: 90rpx 30rpx 0;
		box-sizing: border-box;
	}

	.container {
		position: relative;
		border-radius: 10rpx;
		background-color: white;
		padding: 60rpx 30rpx 40rpx;

		.status-icon {
			position: absolute;
			top: 0;
			left: 50%;
			transform: translate(-50%, -50%);
			width: 120rpx;
			height: 120rpx;
			font-size: 50rpx;
			color: white;
			text-align: center;
			line-height: 120rpx;
			font-weight: bold;
			border-radius: 50%;

			&.fail {
				background-color: $redColor;
			}

			&.success {
				background-color: $greenColor;
			}
		}

		.pay-text {
			display: block;
			font-size: 30rpx;
			text-align: center;
			font-weight: bold;
			margin-top: 40rpx;
		}

		.descriptions {
			margin-top: 80rpx;

			&-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 15rpx 0;

				.label {
					font-size: 28rpx;
				}

				.text {
					font-size: 28rpx;
					color: #888;
				}
			}
		}

		.btn-group {
			margin-top: 100rpx;

			.btn {
				display: block;
				height: 80rpx;
				border-radius: 40rpx;
				font-size: 28rpx;
				line-height: 80rpx;
				text-align: center;
				box-sizing: border-box;
				transition: transform 0.2s;

				&:active {
					transform: scale(0.95);
				}

				&+.btn {
					margin-top: 20rpx;
				}

				&.fill-btn {
					color: white;
					background-color: $redColor;
				}

				&.border-btn {
					color: $redColor;
					background-color: transparent;
					border: 2rpx solid $redColor;
				}
			}
		}
	}
</style>